package cn.kn.triage.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * @author yinzn
 * @create 2020-10-16 15:42
 */


public class BeanCopy {
    public static <T,S> T beanCopy(S scurce, Supplier<T> target){
        T t =target.get();
        BeanUtils.copyProperties(scurce,t);
        return t;
    }

    public static <T,S> List<T> beanCopy(List<S> sources,Supplier<T> target){
       return sources.stream()
               .map(s->BeanCopy.beanCopy(s,target))
               .collect(Collectors.toList());
    }
}
